using Mapster;
using AhCha.Fortunate.ModelsDto;
using AhCha.Fortunate.Entity.MySQL;
using AhCha.Fortunate.IService.MySQL;
using AhCha.Fortunate.Repositories.SqlSugar;
using AhCha.Fortunate.ModelsDto.MySQL.ApiExceptionLogDto;


namespace AhCha.Fortunate.Service.MySQL
{
    public class ApiExceptionLogService : BaseServices<ApiExceptionLog>, IApiExceptionLogService
    {
        private readonly SqlSugarRepository<ApiExceptionLog> _TEntityRep;
        public ApiExceptionLogService(SqlSugarRepository<ApiExceptionLog> TEntityRep) => _TEntityRep = TEntityRep;

        /// <summary>
        /// 获取接口异常记录日志
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task<SqlSugarPagedList<ApiExceptionLogOutput>> GetApiExceptionLogPage(QueryApiExceptionLogInput input)
        {
            using var db = SqlSugarContext.GetInstance(GetMySQLConn);
            return await db.Queryable<ApiExceptionLog>().Select<ApiExceptionLogOutput>().ToPagedListAsync(input.PageIndex, input.PageSize);
        }

        /// <summary>
        /// 新增ApiExceptionLog数据
        /// </summary>
        public async Task PostApiExceptionLog(PostApiExceptionLogInput input)
        {
            using var db = SqlSugarContext.GetInstance(GetMySQLConn);
            var entity = input.Adapt<ApiExceptionLog>();
            await db.Insertable<ApiExceptionLog>(entity).ExecuteCommandAsync();
        }
    }
}
